package com.sunchangming.rpcgen;

public class Types {
	private static volatile Types instance = null;

	private final java.util.Map<String, Type> types = new java.util.TreeMap<String, Type>();

	static void init() {
		instance = new Types();
		instance.add("boolean", new TypeBoolean());
		instance.add("byte", new TypeByte());
		instance.add("string", new TypeString());
		instance.add("double", new TypeDouble());
		instance.add("float", new TypeFloat());
		instance.add("int", new TypeInt());
		instance.add("long", new TypeLong());
		instance.add("short", new TypeShort());

		instance.add("vector", new TypeVector());
		instance.add("set", new TypeSet());
		instance.add("list", new TypeList());
		instance.add("map", new TypeMap());

		//instance.add("binary", new TypeBinary());
	}

	/**
	 * 
	 * @param fullName
	 * @param t
	 */
	void add(String fullName, Type t) {
		if (types.put(fullName, t) != null) {
			throw new RuntimeException("重复的类型" + fullName);
		}
	}

	Type get(String fullName) {
		return types.get(fullName);
	}

	public static Types getInstance() {
		return instance;
	}
}
